package com.作业.Day2;

import java.util.Scanner;

public class Homework4 {
    public static void main(String[] args) {
        while (true) {
            System.out.println("请选择你购买的商品编号");
            System.out.println("1.T恤     2.网球鞋      3.网球拍");
            System.out.println("********************************");
            System.out.print("请输入商品编号:");
            Scanner scanner = new Scanner(System.in);
            int i = scanner.nextInt();
            System.out.print("请输入购买数量:");
            int num= scanner.nextInt();
            int sum=0;//应付金额
            switch (i) {
                case 1:
                     sum=234*num;
                    System.out.println("T恤￥234     数量为"+num+"合计为￥"+sum);
                    break;
                case 2:
                    sum=100*num;
                    System.out.println("网球鞋￥100     数量为"+num+"合计为￥"+sum);
                    break;
                case 3:
                    sum=50*num;
                    System.out.println("网球拍￥50     数量为"+num+"合计为￥"+sum);
                    break;
            }
            System.out.println("是否继续(y/n)");
            String next = scanner.next();
            if (next.equals("n")) {
                /**
                 * 计算找钱
                 */
                 double discount=0.8;
                System.out.println("折扣:"+discount);
               Double Amount_paid= discount*sum;
                System.out.println("应付金额"+Amount_paid);
                System.out.print("实付金额");
                Double amount=scanner.nextDouble();//实付金额
                Double back=amount-Amount_paid;
                if(back>=0) {
                    String format = String.format("%.2f", back);
                    System.out.println("找钱: " + format);
                }
                else {
                    System.out.println("余额不足，请重新选择");
                    continue;
                }
                                break;
            }
        }

    }


}
